using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using Bymed.SpineScan.DataModel;

namespace Bymed.SpineScan.Repository.EntityFramework.Mapping
{
    public class TestResultMap : EntityTypeConfiguration<TestResult>
    {
        public TestResultMap()
        {
            // Primary Key
            this.HasKey(t => t.ID);

            // Properties
            this.Property(t => t.TestTimestamp)
                .IsRequired()
                .HasMaxLength(50);

            this.Property(t => t.TestItemName)
                .IsRequired()
                .HasMaxLength(50);

            this.Property(t => t.ResultRawData)
                .IsRequired()
                .HasMaxLength(100);

            this.Property(t => t.Graph)
                .HasMaxLength(2000);

            // Table & Column Mappings
            this.ToTable("TestResult");
            this.Property(t => t.ID).HasColumnName("ID");
            this.Property(t => t.TestTimestamp).HasColumnName("TestTimestamp");
            this.Property(t => t.TestItemName).HasColumnName("TestItemName");
            this.Property(t => t.ResultRawData).HasColumnName("ResultRawData");
            this.Property(t => t.Graph).HasColumnName("Graph");

            // Relationships
            this.HasRequired(t => t.TestTracking)
                .WithMany(t => t.TestResults)
                .HasForeignKey(d => d.TestTimestamp);
        }
    }
}
